// sharedStore.js
import {defineStore} from 'pinia';

export const useFillStore = defineStore({
    id: 'app-fill',
    state: () => ({
        fillData: null,
    }),
    actions: {
        setFillData(data) {
            this.fillData = data;
        },
    },
});

interface SelectState {
    SData: Object[]; // 举例，可以根据实际情况修改
    op: String,
}

export const useSelectedStore = defineStore({
    id: 'app-select',
    state: (): SelectState => ({
        SData: [],
        op: '',
    }),
    actions: {

        delSelectedData(id,iweek) {

            // const index = this.SData.findIndex(item => item.id == id);
            for (let sDataKey in this.SData) {
                if((this.SData[sDataKey].id==id)&&(this.SData[sDataKey].iWeek==iweek))
                {
                    this.SData.splice(sDataKey, 1);
                    break
                }
            }
            this.op = this.SData.length > 0 ? "提交" : ''
        },

        setSelectedData(type, data: Object) {

            this.delSelectedData(data.id,data.iWeek)
            if (type == 1) {
                this.SData.push({
                    "id": data.id,
                    "iWeek": data.iWeek,
                    select: {
                        "weekSelected": data.weekSelected,
                        "daySelected": data.daySelected,
                        "partSelected": data.partSelected,
                        "floorSelected": data.floorSelected,
                        "roomSelected": data.roomSelected
                    }
                })
            } else {
                // 调课
                this.SData.push({
                    "id": data.id,
                    "iWeek": data.iWeek,
                    select: {
                        "academySelected": data.academySelected,
                        "teacherSelected": data.teacherSelected,
                    }
                })
            }
            console.log("SelectedData_fillInfo", this.SData)

            this.op = this.SData.length > 0 ? "提交" : ''
        },
        clearSelectedData() {
            this.SData = []
            this.op = this.SData.length > 0 ? "提交" : ''
            console.log("SDataop", this.op)
        },

    }
});

